package com.yanqu.road.server.cmd.blacklist;

import com.yanqu.road.pb.player.BlacklistProto;
import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.BlacklistModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

/**
 * @author ：zfr
 * @date ：2021/4/6 18:36
 */
@Cmd(code = GameProtocol.S_BLACKLIST_GET_USER_INFO_CROSS_RESP, desc = "跨服返回被拉黑的玩家的信息")
public class GetBlacklistUserInfoRespCmd extends AbstractCommand {
    private PlayerProto.PlayerBaseTempMsg baseUserInfo;
    private long blackUserId;
    private int type;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        BlacklistProto.BlacklistAddCrossRespMsg reqMsg = BlacklistProto.BlacklistAddCrossRespMsg.parseFrom(packet.getBytes());
        baseUserInfo = reqMsg.getBaseUserInfo();
        blackUserId = reqMsg.getBlackUserId();
        type = reqMsg.getType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(BlacklistModule.class).addCrossBlacklist(type, baseUserInfo, blackUserId);
    }

    @Override
    public void sendData(GamePlayer player) {
        BlacklistProto.BlacklistAddRespMsg.Builder respMsg = BlacklistProto.BlacklistAddRespMsg.newBuilder();
        respMsg.setRet(ret);
        respMsg.setBlacklistUserId(blackUserId);
        respMsg.setBlacklistUserServerId(baseUserInfo.getServerId());
        respMsg.setType(type);
        player.sendPacket(Protocol.U_BLACKLIST_ADD, respMsg);
    }
}
